package com.huiSu.jedis.util;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: H_tao_X
 * Date: 2023-01-17
 * Time: 18:35
 */
public class JedisConnectionFactory {

    private static final JedisPool jedispool;

    static {
        // 1.配置连接池
        JedisPoolConfig poolConfig = new JedisPoolConfig();
        // 最大连接
        poolConfig.setMaxTotal(8);
        // 最大空闲连接
        poolConfig.setMaxIdle(8);
        // 最小空闲连接
        poolConfig.setMinIdle(0);
        // 设置等待时间
        poolConfig.setMaxWaitMillis(1000);
        // 2.创建连接池对象
        jedispool = new JedisPool
                (poolConfig,"42.193.18.121",6379,1000);

    }
    // 3.获取 Jedis对象
    public static Jedis getJedis() {
        return jedispool.getResource();
    }

}
